home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Lib / CDEFs / StatTextCDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-20  |  5.6 KB  |  301 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:         StatTextCDEF.c
  5. ** Written by:      Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11.  
  12.  
  13. /*****************************************************************************/
  14.  
  15.  
  16.  
  17. #ifndef __CONTROLS__
  18. #include <Controls.h>
  19. #endif
  20.  
  21. #ifndef __FONTS__
  22. #include <Fonts.h>
  23. #endif
  24.  
  25. #ifndef __GESTALTEQU__
  26. #include <GestaltEqu.h>
  27. #endif
  28.  
  29. #ifndef __MEMORY__
  30. #include <Memory.h>
  31. #endif
  32.  
  33. #ifndef __OSUTILS__
  34. #include <OSUtils.h>
  35. #endif
  36.  
  37. #ifndef __TEXTEDIT__
  38. #include <TextEdit.h>
  39. #endif
  40.  
  41. #ifndef __WINDOWS__
  42. #include <Windows.h>
  43. #endif
  44.  
  45.  
  46.  
  47. pascal long            main        (short varCode, ControlHandle ctl, short msg, long parm);
  48. pascal long            CStatTextCtl(short varCode, ControlHandle ctl, short msg, long parm);
  49. static pascal void    NoRect(GrafVerb verb, Rect *r);
  50. static Boolean        GetCtlColor(ControlHandle ctl, short part, RGBColor *rgb);
  51. static short        GetQDVersion(void);
  52. static RgnHandle    ScreenDepthRegion(short depth);
  53.  
  54.  
  55.  
  56. /*****************************************************************************/
  57.  
  58.  
  59.  
  60. #pragma segment StatTextCDEF
  61. #if THINK_C
  62. pascal long    main(short varCode, ControlHandle ctl, short msg, long parm)
  63. #else
  64. pascal long    CStatTextCtl(short varCode, ControlHandle ctl, short msg, long parm)
  65. #endif
  66. {
  67.     Rect        rct;
  68.     WindowPtr    curPort;
  69.     short        txFont, txSize, txMode, mode, depth;
  70.     Style        txFace;
  71.     QDProcs        qdp;
  72.     QDProcsPtr    oldqdp;
  73.     Boolean        doColor;
  74.     RGBColor    rgb, oldrgb;
  75.     RgnHandle    oldClip, newClip, rgn1, rgn2;
  76.     Point        pt;
  77.  
  78.     rct = (*ctl)->contrlRect;
  79.  
  80.     switch (msg) {
  81.  
  82.         case drawCntl:
  83.  
  84.             GetPort(&curPort);
  85.             GetClip(oldClip = NewRgn());
  86.  
  87.             if (varCode & 0x0002) {                /* Figure out where drawing is allowed. */
  88.                 depth = (*ctl)->contrlMin;
  89.                 if (depth < 1) depth = 1;
  90.                 newClip = ScreenDepthRegion(depth);
  91.                 pt.h = pt.v = 0;
  92.                 GlobalToLocal(&pt);
  93.                 OffsetRgn(newClip, pt.h, pt.v);
  94.                 SectRgn(oldClip, newClip, newClip);
  95.                 SetClip(newClip);
  96.                 DisposeRgn(newClip);
  97.             }
  98.  
  99.             txFont = curPort->txFont;
  100.             txFace = curPort->txFace;
  101.             txSize = curPort->txSize;
  102.             if (!(varCode & useWFont)) {
  103.                 TextFont(systemFont);
  104.                 TextFace(normal);
  105.                 TextSize(0);
  106.             }
  107.  
  108.             if (varCode & 0x0001) {
  109.                 if (oldqdp = curPort->grafProcs)
  110.                     BlockMove(oldqdp, &qdp, sizeof(QDProcs));
  111.                 else
  112.                     SetStdProcs(&qdp);
  113.                 qdp.rectProc = (QDPtr)NoRect;
  114.                 curPort->grafProcs = &qdp;
  115.                 txMode = curPort->txMode;
  116.                 TextMode(srcOr);
  117.             }
  118.  
  119.             HLock((Handle)ctl);
  120.             mode = (varCode & 0x0004) ? teCenter : teFlushDefault;
  121.  
  122.             if (doColor = GetCtlColor(ctl, cTextColor, &rgb)) {
  123.                 GetForeColor(&oldrgb);
  124.                 RGBForeColor(&rgb);
  125.                 depth = (*ctl)->contrlMax;
  126.                 if (depth < 1) depth = 1;
  127.                 newClip = ScreenDepthRegion(depth);
  128.                 pt.h = pt.v = 0;
  129.                 GlobalToLocal(&pt);
  130.                 OffsetRgn(newClip, pt.h, pt.v);
  131.                 rgn1 = NewRgn();
  132.                 rgn2 = NewRgn();
  133.                 GetClip(rgn1);
  134.                 SectRgn(rgn1, newClip, rgn2);
  135.                 SetClip(rgn2);
  136.                 TextBox((*ctl)->contrlTitle + 1, (*ctl)->contrlTitle[0], &rct, mode);
  137.                 DiffRgn(rgn1, newClip, rgn2);
  138.                 SetClip(rgn2);
  139.                 DisposeRgn(newClip);
  140.                 DisposeRgn(rgn1);
  141.                 DisposeRgn(rgn2);
  142.                 RGBForeColor(&oldrgb);
  143.             }
  144.  
  145.             TextBox((*ctl)->contrlTitle + 1, (*ctl)->contrlTitle[0], &rct, mode);
  146.  
  147.             HUnlock((Handle)ctl);
  148.  
  149.             if (varCode & 0x0001) {
  150.                 curPort->grafProcs = oldqdp;
  151.                 TextMode(txMode);
  152.             }
  153.  
  154.             TextFont(txFont);
  155.             TextFace(txFace);
  156.             TextSize(txSize);
  157.  
  158.             SetClip(oldClip);
  159.             DisposeRgn(oldClip);
  160.             break;
  161.  
  162.         case testCntl:
  163.             break;
  164.  
  165.         case calcCRgns:
  166.         case calcCntlRgn:
  167.             if (msg == calcCRgns)
  168.                 parm &= 0x00FFFFFF;
  169.             RectRgn((RgnHandle)parm, &rct);
  170.             break;
  171.  
  172.         case initCntl:
  173.             break;
  174.  
  175.         case dispCntl:
  176.             break;
  177.  
  178.         case posCntl:
  179.             break;
  180.  
  181.         case thumbCntl:
  182.             break;
  183.  
  184.         case dragCntl:
  185.             break;
  186.  
  187.         case autoTrack:
  188.             break;
  189.     }
  190.  
  191.     return(0);
  192. }
  193.  
  194.  
  195.  
  196. /*****************************************************************************/
  197.  
  198.  
  199.  
  200. #pragma segment StatTextCDEF
  201. static pascal void    NoRect(GrafVerb verb, Rect *r)
  202. {
  203. #pragma unused (verb, r)
  204. }
  205.  
  206.  
  207.  
  208. /*****************************************************************************/
  209.  
  210.  
  211.  
  212. #pragma segment StatTextCDEF
  213. static Boolean    GetCtlColor(ControlHandle ctl, short part, RGBColor *rgb)
  214. {
  215.     Boolean            ret;
  216.     AuxCtlHandle    aux;
  217.     CCTabHandle        ctab;
  218.     ColorSpec        cspec;
  219.     short            i;
  220.  
  221.     rgb->red = rgb->green = rgb->blue = 0;
  222.  
  223.     if (!GetQDVersion()) return(false);
  224.  
  225.     if (ret = GetAuxCtl(ctl, &aux)) {
  226.         if (ctab = (*aux)->acCTable) {
  227.             for (i = (*ctab)->ctSize; cspec = (*ctab)->ctTable[i], i; --i)
  228.                 if (cspec.value == part) break;
  229.             *rgb = cspec.rgb;
  230.         }
  231.         else ret = false;
  232.     }
  233.  
  234.     return(ret);
  235. }
  236.  
  237.  
  238.  
  239. /*****************************************************************************/
  240.  
  241.  
  242.  
  243. #pragma segment StatTextCDEF
  244. static short    GetQDVersion(void)
  245. {
  246.     long    gestaltResult;
  247.  
  248.     if (Gestalt(gestaltQuickdrawVersion, &gestaltResult))
  249.         gestaltResult = 0;
  250.  
  251.     return((gestaltResult >> 8) & 0xFF);
  252. }
  253.  
  254.  
  255.  
  256. /*****************************************************************************/
  257.  
  258.  
  259.  
  260. #pragma segment StatTextCDEF
  261. static RgnHandle    ScreenDepthRegion(short depth)
  262. {
  263.     RgnHandle        retRgn, tmpRgn;
  264.     GDHandle        device;
  265.     PixMapHandle    pmap;
  266.     Rect            rct;
  267.     GrafPtr            mainPort;
  268.  
  269.     retRgn = NewRgn();
  270.  
  271.     if (!GetQDVersion()) {
  272.         if (depth == 1) {
  273.             GetWMgrPort(&mainPort);
  274.             rct = mainPort->portRect;
  275.             RectRgn(retRgn, &rct);
  276.         }
  277.     }
  278.     else {
  279.         tmpRgn = NewRgn();
  280.         for (device = GetDeviceList(); device; device = GetNextDevice(device)) {
  281.             if (
  282.                 (TestDeviceAttribute(device, screenDevice)) &&
  283.                 (TestDeviceAttribute(device, screenActive))
  284.             ) {
  285.                 pmap = (*device)->gdPMap;
  286.                 if ((*pmap)->pixelSize >= depth) {
  287.                     rct = (*device)->gdRect;
  288.                     RectRgn(tmpRgn, &rct);
  289.                     UnionRgn(retRgn, tmpRgn, retRgn);
  290.                 }
  291.             }
  292.         }
  293.         DisposeRgn(tmpRgn);
  294.     }
  295.  
  296.     return(retRgn);
  297. }
  298.  
  299.  
  300.  
  301.